package com.glhtgyxy.biyesheji.Service;

import com.glhtgyxy.biyesheji.Mapper.merchantMapper;
import com.glhtgyxy.biyesheji.Pojo.merchant;
import com.glhtgyxy.biyesheji.Pojo.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class merchantService {
    @Autowired
    merchantMapper mapper;

    public ArrayList<merchant> findAllMerchant(){

        return  mapper.findAllMerchant();
    }
    public Boolean updateMerchant(int id,
                                  String name,
                                  String account,
                                  String password){

        return  mapper.updateMerchant(id, name,account,password)>0?true:false;
    }

    public Boolean merchantaddhouse(String housename,
                                    String addr,
                                    String price,
                                    String bedroom,
                                    String service,
                                    ArrayList<String> imgname,
                                    String masterid
    ){
        String img="";
        for (int i = 0; i < imgname.size(); i++) {
            img=img+imgname.get(i);
            if (i<imgname.size()-1)
            {
                img=img+",";
            }
        }
        int zhurenid = Integer.parseInt(masterid);
        return  mapper.merchantaddhouse(housename, addr,price,bedroom,service,img,zhurenid)>0?true:false;
    }

    public Boolean addMerchant(String name,
                               String account,
                               String password){

        return  mapper.addMerchant(name,account,password)>0?true:false;
    }
    public Boolean deleteMerchant(int id){

        return  mapper.deleteMerchant(id)>0?true:false;
    }

    public Boolean shanchufangyuan(int houseid){

        return  mapper.shanchufangyuan(houseid)>0?true:false;
    }

    public ArrayList<merchant> findMerchant(String searchtext){
        System.out.println("开始模糊查找用户："+searchtext);
        return mapper.findMerchant(searchtext);
    }
}
